<script lang="ts" setup>
import { otherApi } from '@/request/api'
import { useHideLoading, useLoading, useNav, useToast } from '@/utils'
import { to } from 'await-to-js'

async function handldPreviewPDF() {
  // #ifdef MP-KUAISHOU
  useNav('/webview', { src: encodeURIComponent(`${import.meta.env.VITE_H5_PDF_URL}`) })
  // #endif
  // #ifndef MP-KUAISHOU
  useLoading(true)
  const [apiErr, apiRes] = await to(otherApi.hetong())
  useHideLoading()
  if (apiErr) {
    return
  }
  useLoading(true)
  const [downloadErr, downloadRes] = await to(uni.downloadFile({ url: apiRes }))
  useHideLoading()
  if (downloadErr) {
    return
  }
  uni.openDocument({ filePath: downloadRes.tempFilePath })
  // #endif
}
</script>

<template>
  <view class="px-30px py-20px">
    <view class="mt-10px rd-16px bg-white px-20px">
      <view class="flex items-center px-10px" @click="handldPreviewPDF">
        <view class="text-26px lh-90px">租赁服务协议</view>
        <view class="i-ri:arrow-right-wide-line ml-a text-#6"></view>
      </view>
      <view class="flex items-center b-t-1px b-t-#e0 b-t-solid px-10px" @click="useNav('/agreement/yonghushouquan')">
        <view class="text-26px lh-90px">用户授权协议</view>
        <view class="i-ri:arrow-right-wide-line ml-a text-#6"></view>
      </view>
      <view class="flex items-center b-t-1px b-t-#e0 b-t-solid px-10px" @click="useNav('/agreement/yonghuzhuce')">
        <view class="text-26px lh-90px">用户注册协议</view>
        <view class="i-ri:arrow-right-wide-line ml-a text-#6"></view>
      </view>
      <view class="flex items-center b-t-1px b-t-#e0 b-t-solid px-10px" @click="useNav('/agreement/huaruizhengxin')">
        <view class="text-26px lh-90px">华瑞征信协议</view>
        <view class="i-ri:arrow-right-wide-line ml-a text-#6"></view>
      </view>
      <view class="flex items-center b-t-1px b-t-#e0 b-t-solid px-10px" @click="useNav('/agreement/yonghudanbao')">
        <view class="text-26px lh-90px">用户担保协议</view>
        <view class="i-ri:arrow-right-wide-line ml-a text-#6"></view>
      </view>
    </view>
  </view>
</template>

<style lang="less" scoped></style>
